<?php
//Démarrage de la session
session_start();
	
$id = $_GET['id'];

//Connexion à la BDD
include ("../../commun_shop/utils/settings_bdd_shop.php");
mysql_connect($host_bd, $id_bd , $mdp_bd);
mysql_select_db("vanadium");mysql_query("SET NAMES 'UTF8'");

$id_shop = $_SESSION['id_shop_connecte'];

$retour_idshop = mysql_query("SELECT id FROM shop WHERE id_shop='$id_shop'") or die(mysql_error()) ;
$idshop = mysql_fetch_array($retour_idshop);
$idshop = $idshop['id'];
$retour_produit = mysql_query("SELECT * FROM produits WHERE id='$id' AND id_shop='$idshop' ") or die(mysql_error()) ;
$produit = mysql_fetch_array($retour_produit);
$retour_max_position_tab = mysql_query("SELECT position_tab FROM produits WHERE id_shop='$idshop' AND categorie='".$produit['categorie']."' ORDER BY position_tab DESC LIMIT 1") or die(mysql_error()) ;
$max_position_tab = mysql_fetch_array($retour_max_position_tab);

$retour_categories = mysql_query("SELECT * FROM categories_produits WHERE id_shop='$idshop'") or die(mysql_error()) ;

//Fermeture de la connexion
mysql_close();

echo"
<div id='edition_prod'>
	<form method='POST' action='../commun_shop/modules/traitement_modif_produit.php' name='modif'>
		<input type='hidden' name='id_prod' value='$id'/>
		<table>
			<tr>
				<td>Nom du Produit : </td>
				<td><input type='text' name='nom_prod' value='".$produit['id_produit']."'/></td>
			</tr>
			<tr>
				<td>Categorie</td>
				<td>
					<select name='categorie'>";
					
					while($categories = mysql_fetch_array($retour_categories))
					{
						if($categories['id']==$produit['categorie'])
						{
							echo "<option value='".$categories['id']."' selected='selected'>".$categories['categorie']."</option>";
						}
						else
						{
							echo "<option value='".$categories['id']."'>".$categories['categorie']."</option>";
						}	
					}

echo"
					</select>
				</td>
			</tr>
			<tr>
				<td>Prix du Produit : </td>
				<td><input type='text' name='prix_prod' value='".$produit['prix']."'/></td>
				<td class='xs'>€</td>
			</tr>
				<tr>
				<td>Description du Produit : </td>
				<td><input type='text' name='description_prod' value='".$produit['description_produit']."'/></td>
			</tr>
			<tr>
				<td>Activation</td>
				<td>
					<select name='activation'>";
					
					if($produit['actif']==1)
					{
						echo"
						<option value='0'>Désactivé</option>
						<option value='1' selected='selected'>Actif</option>
						";
					}
					else
					{
						echo"
						<option value='0' selected='selected'>Désactivé</option>
						<option value='1'>Actif</option>
						";
					}
				
echo"
					</select>
				</td>
			</tr>
			<tr>
				<td>Placement dans l'Onglet</td>
				<td>
					<select name='position_tab'>";
				
					for($i=1;$i <= $max_position_tab['position_tab'];$i++) 
					{
						if($i==$produit['position_tab'])
						{
							echo "<option value='$i' selected='selected'>$i</option>";
						}
						else
						{
							echo "<option value='$i'>$i</option>";
						}	
					}

echo"
					</select>
				</td>
			</tr>
		</table>
		<input type='hidden' name='id_prod' value='$id'/>
		<input type='submit' name='validation' value='Modifier' id='bouton'/>
	</form>
</div>
";
?>